package kassiopeia.commons.util;

import static org.fest.assertions.Assertions.assertThat;
import java.util.Arrays;
import java.util.List;
import kassiopeia.commons.model.Coordinates;
import kassiopeia.commons.model.plugin.Output;
import kassiopeia.commons.model.plugin.Parameter;
import kassiopeia.commons.model.plugin.PluginDescriptor;

public final class PluginModelUtils {

    public static final Coordinates COORDINATES;

    private static final String PLUGIN_ID = "sample-plugin";
    private static final String PLUGIN_GROUP_ID = "kassiopeia";
    private static final String PLUGIN_VERSION = "1.0";
    private static final String PLUGIN_AUTHOR = "Kassiopeia Team";
    private static final String PLUGIN_DESCRIPTION = "Sample Kassiopeia Plugin";
    private static final String PLUGIN_CLASS = "kassipeia.sample.SamplePlugin";
    private static final String PLUGIN_INPUT_DESCRIPTION = "Input of sample plugin";

    static {
        COORDINATES = new Coordinates(PLUGIN_ID, PLUGIN_GROUP_ID, PLUGIN_VERSION);
    }

    private PluginModelUtils() {
    }

    public static PluginDescriptor getPluginDescriptorWithNullId() {
        PluginDescriptor pluginDescriptor = new PluginDescriptor();

        pluginDescriptor.setCoordinates(COORDINATES);
        pluginDescriptor.setAuthor(PLUGIN_AUTHOR);
        pluginDescriptor.setDescription(PLUGIN_DESCRIPTION);
        pluginDescriptor.setPluginClass(PLUGIN_CLASS);

        pluginDescriptor.setConfiguration(getParameterDescriptors());

        pluginDescriptor.setInputDescription(PLUGIN_INPUT_DESCRIPTION);

        pluginDescriptor.setOutputDescriptors(getOutputDescriptors());

        return pluginDescriptor;
    }

    public static PluginDescriptor getPluginDescriptorWithIdSet() {
        PluginDescriptor pluginDescriptor = getPluginDescriptorWithNullId();
        return pluginDescriptor;
    }

    public static void assertEquals(PluginDescriptor expected, PluginDescriptor actual) {
        assertThat(actual).isNotNull();
        assertThat(actual.getCoordinates()).isEqualTo(expected.getCoordinates());
        assertThat(actual.getAuthor()).isEqualTo(expected.getAuthor());
        assertThat(actual.getInputDescription()).isEqualTo(expected.getInputDescription());
        assertThat(actual.getDescription()).isEqualTo(expected.getDescription());
        assertThat(actual.getPluginClass()).isEqualTo(expected.getPluginClass());
        assertThat(actual.getConfiguration()).hasSize(expected.getConfiguration().size());
        assertThat(actual.getOutputDescriptors()).hasSize(expected.getOutputDescriptors().size());
    }

    private static List<Parameter> getParameterDescriptors() {
        Parameter pd1 = new Parameter();
        pd1.setName("parameterWithDefaultValue");
        pd1.setDescription("This is the parameter with default value.");
        pd1.setDefaultValue("777");

        Parameter pd2 = new Parameter();
        pd2.setName("parameter");

        return Arrays.asList(pd1, pd2);
    }

    private static List<Output> getOutputDescriptors() {
        Output od1 = new Output();
        od1.setDescription("First output of sample plugin");
        od1.setName("sample-output-1");

        Output od2 = new Output();
        od2.setDescription("One more output of sample plugin");
        od2.setName("sample-output-2");

        return Arrays.asList(od1, od2);
    }
}
